<?php
namespace Swiftx\Component\Httpd;
use Swiftx\Component\Application\Kernel as ApplicationKernel;
use Swiftx\Interfaces\Httpd\Kernel as HttpKernel;
use Swiftx\Interfaces\Httpd\Request;
use Swiftx\Interfaces\Httpd\Response;
use Swiftx\Interfaces\Router\Collection;

class Kernel extends ApplicationKernel implements HttpKernel{

    /**
     * 处理一个 HTTP request.
     *
     * @param  Request $request
     * @return Response
     */
    public function handle(Request $request):Response{
        /** @var Response $response */
        $response = $this->fetch(Response::class);
        /** @var Collection $router */
        $router = $this->fetch(Collection::class);
        $router->dispatch($request, $response);
        return $response;
    }

    /**
     * 执行请求生命周期的后续操作
     *
     * @param  Request $request
     * @param  Response $response
     * @return void
     */
    public function terminate(Request $request, Response $response){
        // TODO: Implement terminate() method.
    }

}